/**
 * @file kk-patch.c
 * @author Yao Zongyou <yaozy2010@gmail.com>
 * @date 2010-12-27
 */

#include "dialog.h"

int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, char *cmdLine, int nShow) 
{
	MSG msg = {0};
	dialog_t *p_dialog = new_dialog(hInst);

	if (!p_dialog) {
		/* new_dlgMain() returns NULL if it encounters an error */
		MessageBox(NULL, "Window initialization failed.", "Fatal Error", MB_OK);
		return 0;
	}

	ShowWindow(p_dialog->window, nShow);
	UpdateWindow(p_dialog->window);

	while(GetMessage(&msg, NULL, 0, 0) > 0) {
		/**
		 * IsDialogMessage performs some default keyboard dialog processing
		 * for us and will dispatch any message intended for p_dialog->window
		 * to our window proc.  Anything else causes it to return false - in
		 * which case we Translate and Dispatch as normal. 
		 */
		if (!IsDialogMessage(p_dialog->window, &msg)) {
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}

	delete_dialog(p_dialog); /* Don't forget to call this! */

	return msg.wParam;
}
